package com.collectplus.express.tools;

import android.content.Context;
import android.content.SharedPreferences;

import droid.frame.App;

public class SharedPref {

    // 首页订单提示 (false-未提示， true 已提示)
    public static final String isFirst = "isFirst";
    /**
     * 获取是否是第一次访问<br>
     *
     * @return
     * @type 0 首页 , 1 寄包裹界面 , 2引导页 ,3三步搞定投递袋界面 4,新手拍照引导界面
     */
    public static boolean isFirstOpen(int type) {
        Context context = App.getContext();
        SharedPreferences preferences = context.getSharedPreferences(context.getPackageName(), Context.MODE_PRIVATE);
        // 首次访问
        boolean result = preferences.getBoolean(isFirst + "_" + type, true);
        return result;
    }

    /**
     * 设置指定type的页面的访问状态
     *
     * @param type
     * @param open
     */
    public static void setFirstOpen(int type, boolean open) {
        put(isFirst + "_" + type, open);
    }

    public static void put(String key, String value) {
        Context context = App.getContext();
        SharedPreferences preferences = context.getSharedPreferences(context.getPackageName(), Context.MODE_PRIVATE);
        preferences.edit().putString(key, value).commit();
    }

    public static String get(String key) {
        Context context = App.getContext();
        SharedPreferences preferences = context.getSharedPreferences(context.getPackageName(), Context.MODE_PRIVATE);
        String value = preferences.getString(key, "");
        return value;
    }

    public static void put(String key, boolean value) {
        Context context = App.getContext();
        SharedPreferences preferences = context.getSharedPreferences(context.getPackageName(), Context.MODE_PRIVATE);
        preferences.edit().putBoolean(key, value).commit();
    }

    public static boolean getBoolean(String key) {
        Context context = App.getContext();
        SharedPreferences preferences = context.getSharedPreferences(context.getPackageName(), Context.MODE_PRIVATE);
        boolean value = preferences.getBoolean(key, false);
        return value;
    }
    public static boolean getReceiveCodeBoolean(String key) {
        Context context = App.getContext();
        SharedPreferences preferences = context.getSharedPreferences(context.getPackageName(), Context.MODE_PRIVATE);
        boolean value = preferences.getBoolean(key, true);
        return value;
    }
    public static void clearData() {
        Context context = App.getContext();
        SharedPreferences preferences = context.getSharedPreferences(context.getPackageName(), Context.MODE_PRIVATE);
        preferences.edit().clear().commit();
    }

}
